//
//  YeeShopDetailTipTableViewCell.m
//  YeeShopProject
//
//  Created by CoderYee on 2017/3/16.
//  Copyright © 2017年 CoderYee. All rights reserved.
//

#import "YeeShopDetailTipTableViewCell.h"
#import "XRCommonBaseCollectionCell.h"

@interface TipTableViewCell : XRCommonBaseCollectionCell
@property(nonatomic,copy)NSString        *keyword;
@property(nonatomic,retain)UILabel       *titleLable;

@end
@implementation TipTableViewCell

- (CGSize)sizeForCell {
    //宽度加 heightForCell 为了两边圆角。
    return CGSizeMake([_titleLable sizeThatFits:CGSizeMake(MAXFLOAT, MAXFLOAT)].width + 31, 31);
}
-(void)setKeyword:(NSString *)keyword

{
    _keyword = keyword;
    _titleLable.text = _keyword;
    [self layoutIfNeeded];
    [self updateConstraintsIfNeeded];
    
}
-(void)addOwnView
{
    
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 31/ 2;
    [self.contentView setBackgroundColor:xBackgroundColor];
    _titleLable=[[UILabel alloc] init];
    _titleLable.textColor=kBlackColor;
    _titleLable.textAlignment=NSTextAlignmentCenter;
    _titleLable.font=[UIFont systemFontOfSize:14];
    [self.contentView addSubview:_titleLable];
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
}
@end


@interface YeeShopDetailTipTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) TipTableViewCell *cell;



@end



@implementation YeeShopDetailTipTableViewCell


-(void)addOwnView
{
  
    _titleLable=[[UILabel alloc] init];
    _titleLable.textColor=kBlackColor;
    _titleLable.font=[UIFont Y_systemFontOfSize:14];
    _titleLable.text=@"颜色";
    [self.contentView addSubview:_titleLable];
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.top.equalTo(self.contentView).with.offset(5);
         make.height.mas_equalTo(21);
    }];
    
    UICollectionViewFlowLayout  *layout=[[UICollectionViewFlowLayout alloc] init];
    _collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    [_collectionView setBackgroundColor:kWhiteColor];
    [self.contentView addSubview:_collectionView];
    [_collectionView registerClass:[TipTableViewCell class] forCellWithReuseIdentifier:NSStringFromClass([TipTableViewCell class])];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.equalTo(_titleLable.mas_bottom);
        make.right.bottom.equalTo(self.contentView).with.offset(-5);
        make.left.equalTo(self.contentView).with.offset(5);
    }];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.listArray.count;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return CGSizeZero;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(0, 10);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TipTableViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([TipTableViewCell class]) forIndexPath:indexPath];
    NSString *string=self.listArray[indexPath.item];
    cell.keyword =string;
    //cell.titleLable.text=@"345667888656";
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *string=self.listArray[indexPath.item];
    return  CGSizeMake([NSString caculateWidthWithFont:[UIFont Y_systemFontOfSize:14] text:string]+20, 30) ;
}
-(NSMutableArray *)listArray
{
    if (_listArray==nil)
    {
        _listArray=[[NSMutableArray alloc] initWithArray:@[@"测试数据测试数据",@"云标测试数据签",@"历史记录",@"测试",@"妈妈说标题要长",@"测试数据",@"机智的手哥",@"妈妈说标题要长"]];
    }
    return _listArray;
    
}

@end
